package mycoffee.order.adapter;

import java.util.List;

import mycoffee.order.R;
import mycoffee.order.model.Area;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AreaAdapter extends ArrayAdapter<Area> {
	/** Interface to global information about an application environment. */
	protected Context mContext;
	/** used to instantiate layout XML file into its corresponding View objects. */
	LayoutInflater mInfalInflater;

	public AreaAdapter(Context context, int textViewResourceId,
			List<Area> objects) {
		super(context, textViewResourceId, objects);
		mContext = context;
		mInfalInflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = mInfalInflater.inflate(R.layout.spinner_item, null);
		}

		Area area = getItem(position);
		if (area != null) {
			((TextView) convertView).setText(area
					.getNameFollowCurrentLanguage());
		}
		return convertView;
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {

		convertView = super.getDropDownView(position, convertView, parent);
		Area area = getItem(position);
		if (area != null) {
			((TextView) convertView).setText(area
					.getNameFollowCurrentLanguage());
		}
		return convertView;
	}
}
